{% set current_page='feed' %}

{% extends 'federation/master.html' %}

{#
SPDX-FileCopyrightText:  2020-2021 zPlus <zplus@peers.community>
SPDX-License-Identifier: GPL-2.0-only
#}

{% block page_content %}

    {% if feeds|length == 0 %}
        Your feed is empty.
    {% endif %}

    <div>
        {# This variable is used to keep track of a feed creation date while looping.
         # When the date of a feed changes, we display the day of the post. The end
         # result is that we group feeds by month/day on the UI.
         # HACK: We need to use a dictionary here instead of a scalar value, because
         #     jinja2's block scope won't allow changing of a global scalar variable
         #     from inside the for loop.
         #}
        {% set current_day = { 'value': None } %}

        {% for feed in feeds %}
            {% set feed_day  = feed.created.strftime('%Y-%m-%d') %}

            {# Display the day #}
            {% if feed_day != current_day.value %}
                <div class="font-italic font-weight-bold mb-3 {{ 'mt-5' if loop.index > 1 }}">
                    — {{ feed.created.strftime('%b, %-d %Y') }}
                </div>
                {% if current_day.update({'value': feed_day}) %}{% endif %}
            {% endif %}

            {# Display the feed line #}
            <div class="mb-3">
                {% with feed=feed.content %}
                    <div>{% include 'federation/feed.html' %}</div>
                {% endwith %}

                <div class="font-italic">{{ feed.created.strftime('%H:%M') }}</div>
            </div>
        {% endfor %}
    </div>

{% endblock %}
